﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SharedClientDll.FormShared
{
    public partial class FormEnterMsg : Form
    {
        string _enterMsg = string.Empty;

        int _length = 0;
        //bool _canSee = true;

        public FormEnterMsg()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 输入提示信息
        /// </summary>
        /// <param name="tips"></param>
        public FormEnterMsg(string tips)
        {
            InitializeComponent();
            this.labelTitle.Text = tips;
        }
        /// <summary>
        /// 提示信息和位置
        /// </summary>
        /// <param name="tips"></param>
        /// <param name="point"></param>
        public FormEnterMsg(string tips, Point point)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;
            this.Location = point;
            this.labelTitle.Text = tips;
        }
        /// <summary>
        /// 输入密码
        /// </summary>
        /// <param name="tips"></param>
        /// <param name="canSee"></param>
        public FormEnterMsg(string tips, bool canSee)
        {
            InitializeComponent();
            this.labelTitle.Text = tips;
            //_canSee = canSee;
            if (canSee == false)
                this.textBoxEnter.PasswordChar = '*';
        }
        /// <summary>
        /// 输入长度限制
        /// </summary>
        /// <param name="tips"></param>
        /// <param name="lENGTH"></param>
        public FormEnterMsg(string tips, int lENGTH)
        {
            InitializeComponent();
            this.labelTitle.Text = tips;
            _length = lENGTH;
        }
        /// <summary>
        /// 提示/长度/显示内容
        /// </summary>
        /// <param name="tips"></param>
        /// <param name="length"></param>
        /// <param name="data"></param>
        public FormEnterMsg(string tips, int length, string data)
        {
            InitializeComponent();
            this.labelTitle.Text = tips;
            _length = length;
            this.textBoxEnter.Text = data;
        }

        private void ButtonEnter_Click(object sender, EventArgs e)
        {
            _enterMsg = this.textBoxEnter.Text.Trim();

            if (_length != 0 && _enterMsg.Length != _length)
            {
                MessageBox.Show(string.Format("输入数据不为{0}位", _length));
                this.textBoxEnter.Clear();
                return;
            }

            Close();
        }

        public string GetEnter()
        {
            return _enterMsg;
        }

        private void TextBoxEnter_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
                this.buttonEnter.PerformClick();
        }
    }
}
